package router

import "github.com/gin-gonic/gin"

func InitRoutes() *gin.Engine {
	r := gin.Default()
	// 加载中间件
	r.Use(middlewares...)
	// 加载路由
	for _, route := range routers {
		route(r) // 执行自定义的路由
	}

	return r
}

type Router func(*gin.Engine)

// 存储路由
var (
	routers     = []Router{}
	middlewares = []gin.HandlerFunc{}
)

// Register 注册路由
func Register(route ...Router) {
	routers = append(routers, route...)
}

func Use(handles ...gin.HandlerFunc) {
	middlewares = append(middlewares, handles...)
}
